<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .a{
            text-decoration: none;
            height: 50px;
            line-height: 50px;
            background: skyblue;
            display: inline-block;
            margin: 10px 20px 10px;
        }
        .btn{
            border-color: pink;
        }
    </style>
</head>
<body>
    <div id="app">
        <button class="btn" style="color: purple;">点我插入DOM</button>
        <br>
        <a href="#" class="a">A标签是行内元素</a>
    </div>
</body>
<script>
    let app =document.querySelector('#app')
    let domClone = document.querySelector('.btn').cloneNode(true);
    app.appendChild(domClone);
    let btn = document.querySelectorAll('.btn');
    btn.forEach(el=>{
        el.addEventListener("click",function(){
        let newDom = document.createElement('h1')
        newDom.innerHTML = `我是新增的H1标签<a href="https://www.baidu.com/" style="text-decoration: none;">点我跳转百度</a>`
        app.appendChild(newDom)
      }) 
    })

    let pros = new Promise((resolve, reject)=>{
        reject(88);
    }).then((value)=>{
        console.log(value);
    }).catch((err)=>{
        console.log(err);
    })

    // async function fn(){
    //     console.log(123);
    //     let a =  await fnn();
    //     console.log(a);
    //     return 1
    // }    
    // fn().then((data)=>{
    //     console.log(data);   //总结：async函数会返回一个Promise对象，  async函数并不会阻塞执行栈
    // })
    // function fnn(){
    //     return new Promise((resolve, reject) => {
    //     console.log(456);
    //     resolve('yes')
    //     })
    // }

    function timeout(ms) {
    return new Promise((resolve) => {
        setTimeout(resolve, ms);
        console.log(ms);
    });
    }
    async function asyncPrint(value, ms) {
    await timeout(ms);
    console.log(value);
    }
    asyncPrint('hello world', 3000);


    // for (const k of btn) {
    //     console.log(k);
    // }
    // for(let i=0;i<btn.length;i++){
    //   btn[i].addEventListener("click",function(){
    //     let newDom = document.createElement('h1')
    //     newDom.innerHTML = `我是新增的H1标签<a href="https://www.baidu.com/" style="text-decoration: none;">点我跳转百度</a>`
    //     app.appendChild(newDom)
    //   })  
    // }    
</script>
</html>